package cate.game.activity.specall;

import cate.common.table.pay.PayItemRow;
import cate.common.util.GameResult;
import cate.game.activity.base.core.SubActivitySingle;
import cate.game.activity.specall.msg.SpeCallStarGiftDataResp;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.practice.errorcode.EcResult;

import java.util.List;
import java.util.Map;

@NoteClass("独立卡池召唤-升星数据")
public class SpeCallStarGift extends SubActivitySingle<SpeCallActivity> {
    public List<Integer> getGetRecords() {
        return parent.speCallGlobal.getRecords;
    }

    public Map<Integer, Integer> getBuyRecords() {
        return parent.speCallGlobal.buyRecords;
    }

    public Map<Integer, Boolean> getAvailableGet() {
        return parent.speCallGlobal.availableGet;
    }

    public void onStart() {
        openGift();
    }

    private void openGift() {
        parent.speCallGlobal.openGift();
        noticeUpdate();
    }

    @Override
    public void onEnter() {
        super.onEnter();
        if (!parent.enable()) {
            return;
        }
        openGift();
    }

    public void updateAvailable(String uid) {
        if (parent.speCallGlobal.updateAvailable(uid)) {
            noticeUpdate();
        }
    }

    public GameResult<Void> allowPay(PayItemRow pir) {
        return parent.speCallGlobal.allowPay(pir);
    }

    public void onPaySuccess(PayItemRow payItemRow) {
        parent.speCallGlobal.onPaySuccess(payItemRow);
        noticeUpdate();
    }

    public void noticeUpdate() {
        role.sendNow(new SpeCallStarGiftDataResp(this));
    }

    public void excelCheck() {
        parent.speCallGlobal.excelCheck(getConfigs());
    }

    @JsonIgnore
    private List<Integer> getConfigs() {
        return role.getGame().table.speCall.star.getRows(parent.configTid());
    }



    @JsonIgnore
    public EcResult<Void> getReward(int tid) {
        EcResult<Void> r = parent.speCallGlobal.getReward(tid);
        if (r.ok()) {
            noticeUpdate();
        }
        return r;
    }

    public EcResult<Void> buyItem(int tid, int num) {
        EcResult<Void> r = parent.speCallGlobal.buyItem(tid, num);
        if (r.ok()) {
            noticeUpdate();
        }
        return r;
    }
}
